package com.lancoo.ccas53.arrangecourse.AlgDataSource.DataService.impl;

import com.lancoo.ccas53.arrangecourse.AlgDataSource.DataService.DataService;
import com.lancoo.ccas53.arrangecourse.AlgDataSource.dataprocess.Impl.TeachingClassDataServiceImpl;
import com.lancoo.ccas53.arrangecourse.AlgDataSource.dataprocess.Impl.TimeslotRoomDataServiceImpl;
import com.lancoo.ccas53.arrangecourse.AlgDataSource.dataprocess.TeachingClassDataService;
import com.lancoo.ccas53.arrangecourse.AlgDataSource.dataprocess.TimeslotRoomDataService;
import com.lancoo.ccas53.entity.RuleUsable;
import com.lancoo.ccas53.entity.TaskInfo;
import com.lancoo.ccas53.pojo.dto.*;
import com.lancoo.ccas53.pojo.vo.Campus;
import com.lancoo.ccas53.pojo.vo.WeekDateVo;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Description 数据服务实现类
 * @Author Fortysun
 * @Date 2023/4/13 21:24
 **/
@Component
public class DataServiceImpl implements DataService {
    private TeachingClassDataService teachingClassDataService;
    private TimeslotRoomDataService timeslotRoomDataService;

    public DataServiceImpl() {
        teachingClassDataService = new TeachingClassDataServiceImpl();
        timeslotRoomDataService = new TimeslotRoomDataServiceImpl(teachingClassDataService.getCampusList());
    }

    @Override
    public List<ArrangeTeacherRuleDto> getTeacherRuleList() {
        return teachingClassDataService.getTeacherRuleList(timeslotRoomDataService.getTimeslotList());
    }

    @Override
    public List<ArrangeCourseRuleDto> getCourseRuleList() {
        return teachingClassDataService.getCourseRuleList(timeslotRoomDataService.getTimeslotList());
    }

    @Override
    public List<ArrangeRoomRuleDto> getRoomRuleList(String campusId) {
        //如果不为空，按照校区，获取指定校区的，教室的禁排规则
        if (campusId != null) {
            return timeslotRoomDataService.getRoomRuleMap().get(campusId);
        } else {//获取全部校区的教室的禁排规则
            return timeslotRoomDataService.getRoomRuleMap().entrySet().stream()
                    .flatMap(entry -> entry.getValue().stream())
                    .collect(Collectors.toList());
        }
    }

    @Override
    public List<ArrangeRoomDto> getRoomList(String campusId) {
        //如果不为空，按照校区，获取指定校区的，教室的信息列表
        if (campusId != null) {
            return timeslotRoomDataService.getRoomMap().get(campusId);
        } else {//获取全部校区的教室列表
            return timeslotRoomDataService.getRoomMap().entrySet().stream()
                    .flatMap(entry -> entry.getValue().stream())
                    .collect(Collectors.toList());
        }
    }

    @Override
    public List<ArrangePeriod> getTimeslotList() {
        return timeslotRoomDataService.getTimeslotList();
    }

    @Override
    public List<ArrangeTeachingClassDto> getTeachingClassList(String campusId) {
        //如果校区id不为空，获取指定校区的教学班信息；
        if (campusId != null) {
            return teachingClassDataService.getTeachingClassMap().get(campusId);
        } else {//获取全校的教学班信息
            return teachingClassDataService.getTeachingClassMap().entrySet().stream().
                    flatMap(entry -> entry.getValue().stream()).collect(Collectors.toList());
        }
    }

    @Override
    public List<Campus> getCampusList() {
        return teachingClassDataService.getCampusList();
    }

    @Override
    public List<RuleUsable> getBaseRuleList() {
        List<RuleUsable> basicRuleList = new ArrayList<>();

        RuleUsable basicRule = new RuleUsable();
        //a:系统无需求，b：集中，c:分散
        basicRule.setOptionType(1);
        basicRule.setCode(9);

        basicRuleList.add(basicRule);

        RuleUsable basicRule1 = new RuleUsable();
        //a:系统无需求，b：集中，c:分散
        basicRule1.setOptionType(1);
        basicRule1.setCode(10);
        basicRuleList.add(basicRule1);

        return basicRuleList;
    }

//    public RuleTeacherSetting getTeacherSetting(Integer taskId) {
//        RuleTeacherSetting teacherSetting =new RuleTeacherSetting();
//        //设置教师单日上课最大数量
//        teacherSetting.setMaxSection(4);
//
//        return teacherSetting;
//    }

    /**
     * 获取学期总周数
     * @param taskId
     * @return
     */
    public WeekDateVo getTermWeeks(Integer taskId) {
        WeekDateVo weekDate = new WeekDateVo();
        //设置总周数
        weekDate.setWeekCount(18);

        return weekDate;
    }

    /**
     * 获取排课选课的计划信息
     * @param taskId 计划id
     * @return
     */
    public TaskInfo getTaskInfo(Integer taskId) {
        TaskInfo taskInfo = new TaskInfo();
        taskInfo.setSchoolId("S-06301530");
        taskInfo.setTerm("2023-202401");
        //0各校区独立排课 1全校统一排课
//        taskInfo.setUnifiedCampus(1);

        return taskInfo;
    }
}
